package bTree.LeetCode;

public class 搜索二维矩阵 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;
        int left = 0, right = m * n - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            int row = mid / m;
            int line = mid % n;
            int comp = matrix[row][line];
            if (comp == target) {
                return true;
            } else if (comp > target) {
                right = mid -1;
            }else {
                left=mid+1;
            }
        }
        return false;
    }
}